// pages/goods/godos-list.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {

    typeId: '',

    searchVal: '',

  },

  bindType(e) {
    const that = this;
    var id = e.currentTarget.dataset.id;
    app.globalData.typeId = id
    that.setData({
      typeId: id
    })
    that.getMoreGoods()
  },

  postSearch() {
    const that = this;
    that.getMoreGoods()
  },

  bindsearch(e) {
    const that = this;
    that.setData({
      searchVal: e.detail.value.trim()
    })
  },

  getMoreGoods(e) {
    const that = this;
    wx.showLoading({
      title: '玩命加载中',
      mask: true,
    })
    wx.request({
      url: app.globalData.url + 'MoreGoods',
      method: 'POST',
      data: {
        gt_id: app.globalData.typeId,
        search: that.data.searchVal,
      },
      success: function (res) {
        if (res.data.info) {
          that.setData({
            moreGoods: res.data.info,
            searchVal: '',
          })
        }
        wx.hideLoading()
      },
    })
  },

  navTo(e) {
    wx.navigateTo({
      url: e.currentTarget.dataset.url,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    const that = this;
    wx.showLoading({
      title: '玩命加载中',
      mask: true,
    })
    wx.request({
      url: app.globalData.url + 'Goodstype',
      method: 'POST',
      success: function (res) {
        if (res.data.info) {
          that.setData({
            goodstype: res.data.info.type,
            typeId: app.globalData.typeId
          })
        }
        that.getMoreGoods()
          wx.hideLoading()
      },
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    const that = this;
    wx.showLoading({
      title: '玩命加载中',
      mask: true,
    })
    wx.request({
      url: app.globalData.url + 'Goodstype',
      method: 'POST',
      success: function (res) {
        if (res.data.info) {
          that.setData({
            goodstype: res.data.info.type,
            typeId: that.data.typeId
          })
        }
        that.getMoreGoods()
        wx.hideLoading()
      },
    })
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  // 监听页面滚动
  onPageScroll: function (res) {

  },

})